package com.hxl.olympic.fragment;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.hxl.olympic.R;
import com.hxl.olympic.adapter.UserInfoAdapter;
import com.hxl.olympic.pojo.User;
import com.xuexiang.xui.widget.button.RippleView;
import com.xuexiang.xui.widget.dialog.DialogLoader;
import com.xuexiang.xui.widget.toast.XToast;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.OnClick;
import me.iwf.photopicker.PhotoPicker;

public class UserInfoFragment extends BaseFragment implements View.OnClickListener {

    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.lv1)
    ListView lv1;
    @BindView(R.id.lv2)
    ListView lv2;
    @BindView(R.id.rv_save)
    RippleView rvSave;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    private String[] names1, names2;
    private UserInfoAdapter infoAdapter1, infoAdapter2;
    private User user;

    @Override
    public void initialize() {
        tvTitle.setText("个人资料");
        names1 = new String[]{"头像", "昵称", "性别", "生日", "简介"};
        names2 = new String[]{"地区", "邮箱", "用户名", "手机号"};
        try {
            infoAdapter1 = new UserInfoAdapter(activity, names1, app.getUserInfo());
            infoAdapter2 = new UserInfoAdapter(activity, names2, app.getUserInfo());
            lv1.setAdapter(infoAdapter1);
            lv2.setAdapter(infoAdapter2);
        } catch (Exception e) {
            e.printStackTrace();
            XToast.normal(activity, "数据获取失败!", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void initViews() {
        lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        PhotoPicker.builder()
                                .setPhotoCount(1)
                                .start(activity, UserInfoFragment.this);
                        break;
                    case 1:

                        break;
                    case 2:
                        break;
                }
            }
        });
    }


    @Override
    public void initData() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_user_info;
    }

    @Override
    @OnClick({R.id.img_back, R.id.rv_save})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_back:
                new Timer().schedule(new TimerTask() {
                    @Override
                    public void run() {
                        fragmentManager.popBackStack();
                    }
                }, 500);
                break;
            case R.id.rv_save:
                //确认对话框
                DialogLoader.getInstance().showConfirmDialog(activity, "确认保存个人资料信息?", "是", (dialog, which) -> {

                }, "否");
                break;
        }
    }

}
